/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.finance.service.impl;

import me.zhengjie.modules.finance.domain.FinanceAd01;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.finance.service.FinanceAd01Service;
import me.zhengjie.modules.finance.domain.dto.FinanceAd01QueryCriteria;
import me.zhengjie.modules.finance.mapper.FinanceAd01Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-26
**/
@Service
@RequiredArgsConstructor
public class FinanceAd01ServiceImpl extends ServiceImpl<FinanceAd01Mapper, FinanceAd01> implements FinanceAd01Service {

    private final FinanceAd01Mapper financeAd01Mapper;

    @Override
    public PageResult<FinanceAd01> queryAll(FinanceAd01QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(financeAd01Mapper.findAll(criteria, page));
    }

    @Override
    public List<FinanceAd01> queryAll(FinanceAd01QueryCriteria criteria){
        return financeAd01Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(FinanceAd01 resources) {
        financeAd01Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(FinanceAd01 resources) {
        FinanceAd01 financeAd01 = getById(resources.getBaz244());
        financeAd01.copy(resources);
        financeAd01Mapper.updateById(financeAd01);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<BigDecimal> ids) {
        financeAd01Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<FinanceAd01> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (FinanceAd01 financeAd01 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("险种类型", financeAd01.getAae140());
            map.put("费款所属期", financeAd01.getAae002());
            map.put("征集有效期", financeAd01.getAae805());
            map.put("收支类型", financeAd01.getAaa039());
            map.put("业务处理类别", financeAd01.getAae710());
            map.put("本地业务处理类别", financeAd01.getBae710());
            map.put("收支金额", financeAd01.getAae719());
            map.put("业务批次号", financeAd01.getAaz617());
            map.put("业务支付批次号", financeAd01.getAaz654());
            map.put("批量支付流水号", financeAd01.getAaz618());
            map.put("单据号", financeAd01.getAae072());
            map.put("数据源表", financeAd01.getBae038());
            map.put("当事人类别", financeAd01.getAaa028());
            map.put("当事人 ID", financeAd01.getAaz010());
            map.put("当事人名称", financeAd01.getAae734());
            map.put("单位编号", financeAd01.getAab001());
            map.put("单位名称", financeAd01.getAab004());
            map.put("单位类型", financeAd01.getAab019());
            map.put("法定代表人证件类型", financeAd01.getAac058());
            map.put("法定代表人证件号码", financeAd01.getAac147());
            map.put("基金收支方式", financeAd01.getAae718());
            map.put("银行行别代码", financeAd01.getAaf200());
            map.put("地方银行行别代码", financeAd01.getAaf216());
            map.put("地方银行名称", financeAd01.getAaf217());
            map.put("银行名称", financeAd01.getAae668());
            map.put("银行户名", financeAd01.getAae009());
            map.put("银行账号", financeAd01.getAae010());
            map.put("银行所在省份", financeAd01.getAab362());
            map.put("银行所在市", financeAd01.getAaf056());
            map.put("人行支付系统行号", financeAd01.getAaf002());
            map.put("摘要", financeAd01.getAad128());
            map.put("数据接收状态", financeAd01.getAae711());
            map.put("锁定标志", financeAd01.getAae825());
            map.put("财务处理标志", financeAd01.getBad006());
            map.put("到账成功标志", financeAd01.getAae456());
            map.put("到账日期", financeAd01.getAab191());
            map.put("支付失败原因", financeAd01.getAae713());
            map.put("实收分配标志", financeAd01.getAae151());
            map.put("到账方式", financeAd01.getAae770());
            map.put("登账明细ID", financeAd01.getBad011());
            map.put("对账流水号", financeAd01.getAaz728());
            map.put("原单据号", financeAd01.getAaz749());
            map.put("会计核算单位", financeAd01.getAad146());
            map.put("账套类别", financeAd01.getAad080());
            map.put("备注", financeAd01.getAae013());
            map.put("创建人", financeAd01.getAae860());
            map.put("创建时间", financeAd01.getAae859());
            map.put("经办人", financeAd01.getAae011());
            map.put("经办人登录ID", financeAd01.getAaz692());
            map.put("经办时间", financeAd01.getAae036());
            map.put("社会保险经办机构编号", financeAd01.getAab034());
            map.put("经办地行政区划代码", financeAd01.getAab360());
            map.put("参保地行政区划代码", financeAd01.getAab359());
            map.put("所属省份行政区划代码", financeAd01.getAaf018());
            map.put("统筹区编码", financeAd01.getAaa027());
            map.put("业务日志ID", financeAd01.getAaz002());
            map.put("批量业务单一日志ID", financeAd01.getAaz005());
            map.put("分库键值", financeAd01.getAaa431());
            map.put("是否线下支付", financeAd01.getBad112());
            map.put("人社银行账号表ID", financeAd01.getAaz670());
            map.put("待遇发放方式", financeAd01.getAae145());
            map.put("当事人邮政地址", financeAd01.getAae006());
            map.put("当事人邮政编码", financeAd01.getAae007());
            map.put("单据批次号", financeAd01.getBaz617());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
